package com.hjq.mallproduct.web;

import com.hjq.mallproduct.entity.CategoryEntity;
import com.hjq.mallproduct.entity.vo.Catlog2VO;
import com.hjq.mallproduct.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @auther HJQ
 */
@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","/index"})
    public String index(Model model){
        List<CategoryEntity> firstLevelList = categoryService.getFirstLevelList();
        model.addAttribute("category",firstLevelList);


        return "index";
    }
    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String , List<Catlog2VO>> indexCatlogJson(){


        return categoryService.getCategoryListInPage();
    }
}
